#ifndef ALERTMANAGER_H
#define ALERTMANAGER_H

#include <QObject>
#include <QSqlDatabase>

class AlertManager : public QObject {
    Q_OBJECT
public:
    explicit AlertManager(QObject* parent = nullptr);

    bool addAlertRule(int deviceId, const QString& description, const QString& condition, const QString& action);
    bool deleteAlertRule(int ruleId);
    void notifyAdmin(int deviceId, const QString& description);

public slots:
    void checkAlertRules(int deviceId, double temperature, double humidity, double light, double co2, double pressure);

signals:
    void alertTriggered(int deviceId, const QString& description);
    void dataUpdated();

private:
    void createAlertRuleTable();
    void createAlertRecordTable();
    bool recordAlert(int deviceId, const QString& content, const QString& status, const QString& note = "");
};

#endif // ALERTMANAGER_H
